package com.decent.ejfadmin.user.dao.provider;

import com.decent.ejfadmin.common.bean.Page;
import org.apache.commons.lang.StringUtils;

import java.util.HashMap;

/**
 * 会员专属管理员
 *
 * @author weicx
 * @date 2018/08/15
 */
@SuppressWarnings("StringBufferMayBeStringBuilder")
public class UserPmDaoProvider {
    /**
     * 查询专属商务计数
     *
     * @param param 参数
     * @return sql
     */
    public String queryUserPmCount(HashMap<String, Object> param) {
        StringBuffer sql = new StringBuffer(100);
        sql.append("select count(1) from yuhuang_pm ");
        generateUserPmQuerySql(sql, param);
        return sql.toString();
    }

    /**
     * 分页查询专属商务
     *
     * @param param 参数
     * @return sql
     */
    public String queryUserPmPage(HashMap<String, Object> param) {
        StringBuffer sql = new StringBuffer(100);
        sql.append("select pm_id id,pm_name name,pm_qq qq,pm_tel tel from yuhuang_pm");
        generateUserPmQuerySql(sql, param);
        Page page = (Page) param.get("page");
        sql.append(" ORDER BY pm_id desc ");
        sql.append(" LIMIT ").append(page.getBeginIndex()).append(" , ").append(page.getSize());
        return sql.toString();
    }

    /**
     * 查询专属商务组织参数
     *
     * @param sql   sql
     * @param param 参数
     */
    private void generateUserPmQuerySql(StringBuffer sql, HashMap<String, Object> param) {
        sql.append(" where pm_id = pm_id ");
        if (StringUtils.isNotBlank((String) param.get("adminName"))) {
            sql.append(" and pm_name = #{adminName} ");
        }
    }
}